
<template>
    <div class="errorpage" ref="bgstar" id="bgstar" >

        <div class="down" @click="gotopage">
          剩余 {{count}} S
        </div>
        <img :src="Img"  alt="" class="myimg">

        <span class="spandot" :style="item" v-for="(item,index) in spanList" :key="index">
        
        </span>
    </div>
</template>

<script setup>
import { onMounted , ref  } from 'vue';
import Img from '../assets/images/404.png'   // 导入的一个图片变量 
import { useRouter }  from 'vue-router'
const router = useRouter()   // 路由对象 
const bgstar = ref();    //绑定一个真实的DOM 
const spanList = ref([]); 
const count = ref(5)

const gotopage = ()=>{
    router.push('/guide')
}

const timeDown = ()=>{
  var timer = setInterval(()=>{
    if(count.value > 0){
      count.value--;

    }else{
      clearInterval(timer)
      timer = null;
      router.push('/guide') 
    }
  },1000)
}

const getAllSpanList = ()=> {
    const width = bgstar.value.clientWidth;
    const height = bgstar.value.clientHeight;

    for(let i=0;i<500;i++){
        var left = width * Math.random();
        var top = height * Math.random();

        var scaler = 1 * Math.random() * 1.5;
        var rate = Math.random() * 2.5 ;
        var opacity = Math.random();

        spanList.value.push({
          left:left+'px',
          top:top+'px',
          animationDelay:rate+"s",
          transform:`scale(${scaler})`,
          background:`rgba(255,255,255,${opacity})`
        })
    }
}

// 初始化执行 
onMounted(()=>{
    getAllSpanList()
    timeDown()
})

</script>


<style lang="scss" scoped>
.errorpage{
  width:100%;
  height:100%;
  background: #000;
  position: relative;
  padding:0 !important;
  overflow: hidden;
  .down{
    position:absolute;
    left:20px;
    top:20px;
    border:1px solid #fff;
    color:#fff;
    width:70px;
    height:30px;
    border-radius:10px;
    text-align:center;
    line-height:30px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    .van-count-down{
        color:#fff;
        margin-right:2px;
        font-size: 12px;
    }
  }
  .dao{
    position: absolute;
    top:20px;
    right:20px;
    ::v-deep .van-circle__text{
        color:#fff !important;
        font-size: 12px !important;
    }
  }
  .myimg{
    width:270px;
    height:270px;
    position: absolute;
    top:0;
    right:0;
    left:0;
    bottom:0;
    margin:auto;
    z-index:10;
  }
  .spandot{
    position: absolute;
    z-index: 100;
    width: 4px;
    height:4px;
    border-radius: 50%;
    animation: flash 3s infinite alternate;
  }
   @keyframes flash {
        from{
            opacity: 0;
        }
        to{
            opacity: 0.5;
        }
    }
}
</style>